package com.danco.training.zaneuskaya.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

import com.danco.training.zaneuskaya.property.PropertyAccess;
import com.danco.training.zaneuskaya.property.PropertyReader;
import com.sun.org.apache.xpath.internal.operations.Bool;

public class ConfigPropertyAnalizer {
	
	public ConfigPropertyAnalizer(Object o){
		
			
			Class cl = o.getClass();
			
			for (Field f: cl.getDeclaredFields()){
				ConfigProperty annotation = f.getAnnotation(ConfigProperty.class);
				if (annotation != null){
					if (annotation.type() == Type.INTEGER){
						try {
							f.get(PropertyAccess.getIntProperty(annotation.propertyName().toString()));
						} catch (IllegalArgumentException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (IllegalAccessException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
					if (annotation.type() == Type.BOOLEAN){
						try {
							f.get(PropertyAccess.getBooleanProperty(annotation.propertyName().toString()));
						} catch (IllegalArgumentException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (IllegalAccessException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
					else{
						try {
							f.get(PropertyAccess.getProperty(annotation.propertyName().toString()));
						} catch (IllegalArgumentException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (IllegalAccessException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
					PropertyReader.filename = annotation.configName().toString();
					
			}
		}
		
	}
}

		
